﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="AddNewBill.aspx.cs" Inherits="masterPages_bill_AddNewBill" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script type="text/javascript">
    function OnValidateCustomerName() {
        var name = document.getElementById("CustomerNameTextBox").value;
        BillWebService.ValidateCustomerName(name, OnValidateCusNameComplete, OnError);
    }
    function OnValidateCusNameComplete(result) {
        if (result) {
            var btn = document.getElementById("AddButton");
            btn.removeAttribute("disabled");
        } else {
            var btn = document.getElementById("AddButton");
            btn.setAttribute("disabled", "disabled");
        }
    }
    function OnAddBtnClick() {
        var itemDL = document.getElementById("SpendItemDropDownList");
        var itemId = itemDL.value;
        var itemName = itemDL.options[itemDL.selectedIndex].text;
        var cusName = document.getElementById("CustomerNameTextBox").value;
        var spendDL = document.getElementById("SpendCountDropDownList");
        var count = spendDL.options[spendDL.selectedIndex].text;
        BillWebService.AddNewSpendItemPrice(cusName, itemName, itemId, count, OnAddNewComplete, OnError);
    }
    function OnAddNewComplete(result) {
        var tbody = document.getElementById("billTbl");
        var tr = document.createElement("tr");

        var td0 = document.createElement("td");
        td0.appendChild(document.createTextNode(result.CustomerName));
        tr.appendChild(td0);

        var td1 = document.createElement("td");
        td1.appendChild(document.createTextNode(result.SpendItemName));
        tr.appendChild(td1);

        var td2 = document.createElement("td");
        td2.appendChild(document.createTextNode(result.SpendItemPrice));
        tr.appendChild(td2);

        var td3 = document.createElement("td");
        td3.appendChild(document.createTextNode(result.SpendItemCount));
        tr.appendChild(td3);

        var td4 = document.createElement("td");
        td4.appendChild(document.createTextNode(result.SpendItemCount * result.SpendItemPrice));
        tr.appendChild(td4);

        var td5 = document.createElement("td");
        var linkNode = '<A id=' + result.BillId + ' onclick="OnRemoveBillClick(this)" href="#">删除</A>';
        td5.innerHTML = linkNode;
        tr.appendChild(td5);
        tbody.appendChild(tr);
    }
    function OnError(result) {
        alert("出错啦！【" + result + "】");
    }

    function OnRemoveBillClick(alink) {
        BillWebService.DeleteSpendItem(alink.id, OnRemoveComplete, OnError);
    }
    function OnRemoveComplete(id) {
        var removeTr = document.getElementById(id);
        var tbody = document.getElementById("billTbl");
        tbody.removeChild(removeTr.parentNode.parentNode);
    }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:ScriptManager ID="ScriptManager" runat="server">
        <Services>
            <asp:ServiceReference Path="~/webServiceASMX/BillWebService.asmx" />
        </Services>
    </asp:ScriptManager>

    <asp:ObjectDataSource ID="SourceSpendItem" runat="server" 
        DataObjectTypeName="SpendItemDetail" DeleteMethod="DeleteEmployees" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetEmployees" 
        TypeName="SpendItemDB" UpdateMethod="UpdateEmployees"></asp:ObjectDataSource>
    <table width="730" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="34" style="background-image:../../images/bj2.gif"><strong>&nbsp;&nbsp;&nbsp;&nbsp;项目添加</strong></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td align="center">
                <span id="Span1">用户：</span>
                <asp:TextBox ID="CustomerNameTextBox" ClientIDMode="Static" runat="server" onblur="OnValidateCustomerName()" />&nbsp;&nbsp;
                <span id="Span2">消费项目：</span>
                <asp:DropDownList ID="SpendItemDropDownList" ClientIDMode="Static" runat="server" 
                    DataSourceID="SourceSpendItem" DataTextField="SpendItemName" 
                    DataValueField="SpendItemId" />&nbsp;&nbsp;
                <span id="Span3">消费数量：</span>
                <asp:DropDownList ID="SpendCountDropDownList" ClientIDMode="Static" runat="server">
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem>2</asp:ListItem>
                    <asp:ListItem>3</asp:ListItem>
                    <asp:ListItem>4</asp:ListItem>
                    <asp:ListItem>5</asp:ListItem>
                    <asp:ListItem>6</asp:ListItem>
                    <asp:ListItem>7</asp:ListItem>
                    <asp:ListItem>8</asp:ListItem>
                    <asp:ListItem>9</asp:ListItem>
                    <asp:ListItem>10</asp:ListItem>
                    <asp:ListItem>11</asp:ListItem>
                    <asp:ListItem>12</asp:ListItem>
                    <asp:ListItem>13</asp:ListItem>
                    <asp:ListItem>14</asp:ListItem>
                    <asp:ListItem>15</asp:ListItem>
                    <asp:ListItem>16</asp:ListItem>
                    <asp:ListItem>17</asp:ListItem>
                    <asp:ListItem>18</asp:ListItem>
                    <asp:ListItem>19</asp:ListItem>
                    <asp:ListItem>20</asp:ListItem>
                </asp:DropDownList>&nbsp;&nbsp;
                <input id="AddButton" type="button" value="确定" disabled="disabled" onclick="OnAddBtnClick();" />
              </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>
                <table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <table width="577" border="1" align="center" cellpadding="5" style="background-color:#999999">
                                <tbody id="billTbl">
                                    <tr>
                                        <td width="100" bgcolor="#E1E1E1">用户名</td>
                                        <td width="250" bgcolor="#E1E1E1">消费项目名称</td>
                                        <td width="90" bgcolor="#E1E1E1">消费项目金额</td>
                                        <td width="50" bgcolor="#E1E1E1">数量</td>
                                        <td width="100" bgcolor="#E1E1E1">总计</td>
                                        <td width="30" bgcolor="#E1E1E1">操作</td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td align="center">
                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/an11.gif" 
                                PostBackUrl="~/masterPages/bill/BillList.aspx" />
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/an3.gif" OnClientClick="OnClearBtnClick();return false;" />
                        </td>
                    </tr>
                </table>
            </td>
          </tr>
        </table>
</asp:Content>

